/*
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.anime.controller;

import java.awt.Color;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.IOException;

import javax.swing.JFrame;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cc.aileron.anime.ApplicationContext;
import cc.aileron.anime.logic.AnimationWriter;

import com.google.inject.Inject;

/**
 * @author Aileron
 */
public class WindowController implements WindowListener
{

    @Override
    public void windowActivated(final WindowEvent e)
    {
        // TODO 自動生成されたメソッド・スタブ

    }

    @Override
    public void windowClosed(final WindowEvent e)
    {
    }

    @Override
    public void windowClosing(final WindowEvent e)
    {
        logger.debug("window close");
        frame.removeAll();
        frame.setBackground(Color.BLACK);
        try
        {
            animationWriter.write();
            logger.debug("window closed");
        }
        catch (final IOException e1)
        {
            logger.error("io-error", e1);
        }
    }

    @Override
    public void windowDeactivated(final WindowEvent e)
    {
        // TODO 自動生成されたメソッド・スタブ

    }

    @Override
    public void windowDeiconified(final WindowEvent e)
    {
        // TODO 自動生成されたメソッド・スタブ

    }

    @Override
    public void windowIconified(final WindowEvent e)
    {
        // TODO 自動生成されたメソッド・スタブ

    }

    @Override
    public void windowOpened(final WindowEvent e)
    {
        // TODO 自動生成されたメソッド・スタブ

    }

    /**
     * @param animationWriter
     * @param context
     */
    @Inject
    public WindowController(
        final AnimationWriter animationWriter,
        final ApplicationContext context)
    {
        this.animationWriter = animationWriter;
        this.frame = context.mainFrame;
    }

    private final AnimationWriter animationWriter;
    private final JFrame frame;
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
}
